﻿
/**
* 命名空间: Game.TDBehaviorTree
*
* 功 能： 延迟节点
* 类 名： NodeWait
*
* Ver 变更日期 负责人 变更内容
* ───────────────────────────────────
* V0.01 2019/12/12 11:53:04  
*/




using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;

namespace Game.TDBehaviorTree
{
    [System.Serializable]
    /// <summary>
    /// 延迟节点
    /// </summary>
    public class NodeWait : NodeAction
    {
        //延迟时间
        [JsonProperty("delayTime")]
        public double m_DelayTime;
        private double m_CurrentTime =0;
        public NodeWait() : base(NodeType.Action)
        {

        }


        public override void Draw(Rect m_Rect, GUIStyle style, NodeValue _value)
        {
            base.Draw(m_Rect, style, _value);
            GUILayout.Label("时间系数");
            m_DelayTime = Convert.ToDouble(UnityEditor.EditorGUILayout.TextField(m_DelayTime.ToString(), UnityEngine.GUILayout.Width(100), UnityEngine.GUILayout.Height(20)));
            _value.m_NodeArgs[0] = m_DelayTime.ToString();
        }

        public override NodeResultType Execute()
        {

            if (m_CurrentTime >= m_DelayTime)
                return NodeResultType.Success;
            else
            {
                m_CurrentTime += UnityEngine.Time.deltaTime;
                return NodeResultType.Running;
               
            }
           
        }


        public override void DeRializable(NodeValue _value)
        {
            base.DeRializable(_value);
            m_DelayTime = Convert.ToDouble(_value.m_NodeArgs[0]);
        }
    }
}
